package com.yunhe.assist.service.impl;

import cn.hutool.core.util.ReUtil;
import com.yunhe.assist.domain.ParkIntroduceContact;
import com.yunhe.assist.repository.ParkIntroduceContactRepository;
import com.yunhe.assist.service.ParkIntroduceContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Objects;

/**
 * @description park_introduce_contact
 * @author dlz
 * @date 2021-11-09
 */
@Service
public class ParkIntroduceContactServiceImpl implements ParkIntroduceContactService {

    @Autowired
    private ParkIntroduceContactRepository parkIntroduceContactRepository;


    @Override
    public int createParkIntroduceContact (ParkIntroduceContact parkIntroduceContact) {
        //校验手机号码格式
        /*if(!ReUtil.isMatch("^[1][3,5,7,8][0-9][0-9]{8}$", parkIntroduceContact.getContactPhone())){
            Assert.isTrue(false, "手机号码（"+parkIntroduceContact.getContactPhone()+"）格式异常");
        }*/
        return parkIntroduceContactRepository.createParkIntroduceContactSelective(parkIntroduceContact);
    }

    @Override
    public int createParkIntroduceContact(long parkIntroduceId, String person, String phone) {
        ParkIntroduceContact parkIntroduceContact = new ParkIntroduceContact(){{
            setParkIntroduceId(parkIntroduceId);
            setContactPerson(person);
            setContactPhone(phone);
        }};
        return this.createParkIntroduceContact(parkIntroduceContact);
    }


    @Override
    public int deleteParkIntroduceContact(int id) {
        return parkIntroduceContactRepository.deleteParkIntroduceContactByPrimaryKey(id);
    }


    @Override
    public int updateParkIntroduceContact(ParkIntroduceContact parkIntroduceContact) {
        return parkIntroduceContactRepository.updateParkIntroduceContactByPrimaryKeySelective(parkIntroduceContact);
    }


    @Override
    public ParkIntroduceContact findParkIntroduceContactById(int id) {
        return parkIntroduceContactRepository.searchParkIntroduceContactByPrimaryKey(id);
    }

    @Override
    public List<ParkIntroduceContact> findList(long parkIntroduceId) {
        return parkIntroduceContactRepository.findList(parkIntroduceId);
    }

    @Override
    public void deleteByIntroduceId(long parkIntroduceId) {
        parkIntroduceContactRepository.deleteByIntroduceId(parkIntroduceId);
    }

    @Override
    public void createParkIntroduceContactBatch(List<ParkIntroduceContact> contacts, Long parkIntroduceId) {
        if(Objects.nonNull(contacts) && !contacts.isEmpty()){
            contacts.forEach(e->{
                e.setParkIntroduceId(parkIntroduceId);
                this.createParkIntroduceContact(e);
            });
        }
    }


}